package org.jix.weblog.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @version 1.0
 * @Author Jix
 * @Date 2024/7/18 15:20
 * @注释
 */

@Configuration
@EnableSwagger2WebMvc
@Profile("dev")
public class Knife4jConfig {

    @Bean("webApi")
    public Docket createApiDoc(){
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                //分组接口
                .apiInfo(buildApiInfo())
                .groupName("web前台接口")
                .select()
                //指定扫描包路径
                .apis(RequestHandlerSelectors.basePackage("org.jix.weblog.web.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;

    }

    /**
     * 构建Api信息
     * @return
     */
    private ApiInfo buildApiInfo(){
        return new ApiInfoBuilder()
                .title("weblog web前台接口文档")
                .description("  by _Jix ------SpringBoot / Vue3.2 / Vite4.3 ")
                .termsOfServiceUrl("暂无")
                .contact(new Contact("Jix", "null", "2145760285@qq.com"))
                .version("test")
                .build();
    }
}
